/**
 * tigerrad
 * fall 2006
 */

#ifndef _AREALIGHT_H
#define _AREALIGHT_H

#include "Util.h"
#include "Light.h"
#include "Model.h"

/**
 * An area light...
 */
class AreaLight : public Light
{
	public:
		/**
		 * Constructor.
		 * @param mat Color properties of the light
		 * @param dir Light direction
		 * @param verts The vertices (assuming a quad) of the light.
		 */
		AreaLight(const Material& mat, const Vec3& dir, const Vec3& up, Vec3 verts[4], float fov) : Light(mat, Vec3(0,0,0), dir, up), _fov(fov)
		{
			assert(_fov > 0.0 && _fov <= 180.0);
			_verts[0] = verts[0];
			_verts[1] = verts[1];
			_verts[2] = verts[2];
			_verts[3] = verts[3];
		}

		/**
		 * Return the ith vertex.
		 */
		Vec3 getVert(unsigned int i) const 
		{ 
			assert(i<4);
			return _verts[i];
		}

		/**
		 * Return the center of the light
		 */
		Vec3 getCenter() const
		{
			Vec3 c(0.0, 0.0, 0.0);
			c += _verts[0];
			c += _verts[1];
			c += _verts[2];
			c += _verts[3];
			return c/4;
		}

		/**
		 * Return the fov of the light, useful for rendering from light.  
		 * This is similar to GL_SPOT_CUTOFF for OpenGL spotlights.
		 */
		float getFov() const { return _fov; }
		

	private:
		Vec3 _verts[4];
		float _fov;
};

typedef boost::shared_ptr<AreaLight> AreaLightPtr;

#endif

